//
//  SHFindDetailViewController.m
//  UI_CarHome
//
//  Created by dllo on 15/11/2.
//  Copyright (c) 2015年 沈浩. All rights reserved.
//

#import "SHFindDetailViewController.h"
#import "SHRightCarModel.h"
#import "SHHandle.h"
#import "SHDetailModel.h"
#import "SHPictureViewController.h"
@interface SHFindDetailViewController ()
@property(nonatomic, retain)UIScrollView *mainScrollView;
@property(nonatomic, retain)NSMutableArray *detailArr;
@property(nonatomic, retain)NSDictionary *dic;
@end

@implementation SHFindDetailViewController

- (void)dealloc
{
    [_mainScrollView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    //     http://mrobot.pcauto.com.cn/xsp/s/auto/info/v4.7/serials.xsp?serialId=9550&regionId=248&hasDealers=1&fmt=json serialId=%@
    //
    //    http://mrobot.pcauto.com.cn/v2/price/nav_pictures?serialGroupId=3524&modelId=null
    self.view.backgroundColor = BACKGROUNDCOLOR;
    self.mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [self.view addSubview:self.mainScrollView];
    self.mainScrollView.contentSize = CGSizeMake(0, HEIGHT);
    [_mainScrollView release];
    
    [self createData];
    
    self.title = @"详情";

    

}

- (void)createData {
    NSString *detailurl = [NSString stringWithFormat:@"http://mrobot.pcauto.com.cn/xsp/s/auto/info/v4.7/serials.xsp?serialId=%@&regionId=248&hasDealers=1&fmt=json", self.rightModel.myId];
   [SHNetWorkingTool getNetWorking:detailurl block:^(id result) {
       NSLog(@"%@", detailurl);
       self.dic = result;
       [self createView];
       
   }];
    
    //奥迪3254
       
}

- (void)createView {
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200)];
    [self.mainScrollView addSubview:imageView];
//    [imageView sd_setImageWithURL:self.dic[@"photo_400x300"]];
    [imageView sd_setImageWithURL:self.dic[@"photo_400x300"] placeholderImage:PLACEPICTURE];
    [imageView release];
    
    // 点击方式
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [imageView addGestureRecognizer:tap];
    [tap release];
    // 图片如果要添加手势,要把图片的用户交互打开,它和label默认是NO
    imageView.userInteractionEnabled = YES;
    
    UILabel *manufacturerLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 170, 150, 30)];
    [imageView addSubview:manufacturerLabel];
    [manufacturerLabel release];
    manufacturerLabel.text = [NSString stringWithFormat:@"%@-%@", self.dic[@"manufacturer"], self.dic[@"kind"]];
    manufacturerLabel.textColor = [UIColor whiteColor];
    
    UILabel *ftcSgPhotoTotalLabel = [[UILabel alloc] initWithFrame:CGRectMake(280, 180, 80, 20)];
    [imageView addSubview:ftcSgPhotoTotalLabel];
    [ftcSgPhotoTotalLabel release];
    ftcSgPhotoTotalLabel.textColor = [UIColor whiteColor];
    ftcSgPhotoTotalLabel.text = [NSString stringWithFormat:@"%@张图 >", self.dic[@"ftcSgPhotoTotal"]];
    ftcSgPhotoTotalLabel.font = [UIFont systemFontOfSize:14];

    
    UILabel *firstLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 200, 60, 30)];
    [self.mainScrollView addSubview:firstLabel];
    [firstLabel release];
    firstLabel.text = @"官方价:";
    firstLabel.textColor = [UIColor grayColor];
    
    UILabel *priceRangeLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 200, 150, 30)];
    [self.mainScrollView addSubview:priceRangeLabel];
    [priceRangeLabel release];
    priceRangeLabel.text = [NSString stringWithFormat:@"%@%@", @"￥", self.dic[@"priceRange"]];
    priceRangeLabel.textColor = [UIColor redColor];
    
    UILabel *secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 235, 90, 30)];
    [self.mainScrollView addSubview:secondLabel];
    [secondLabel release];
    secondLabel.text = @"综合评分:";
    secondLabel.textColor = TEXTCOLOR;
    
    UILabel *sgAverageScoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 235, 70, 30)];
    [self.mainScrollView addSubview:sgAverageScoreLabel];
    [sgAverageScoreLabel release];
    sgAverageScoreLabel.text = [NSString stringWithFormat:@"%@分", self.dic[@"sgAverageScore"]];
    sgAverageScoreLabel.textColor = TEXTCOLOR;
    
    UILabel *cityLabel = [[UILabel alloc] initWithFrame:CGRectMake(220, 235, 40, 30)];
    [self.mainScrollView addSubview:cityLabel];
    [cityLabel release];
    cityLabel.text = self.dic[@"city"];
    cityLabel.textColor = NEWBLUE;
    
    UILabel *pinpaiLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 270, 40, 30)];
    [self.mainScrollView addSubview:pinpaiLabel];
    [pinpaiLabel release];
    pinpaiLabel.text = @"品牌:";
    pinpaiLabel.textColor = TEXTCOLOR;
    
    
    UILabel *serialGroupNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(46, 270, 120, 30)];
    [self.mainScrollView addSubview:serialGroupNameLabel];
    [serialGroupNameLabel release];
    serialGroupNameLabel.text = self.dic[@"serialGroupName"];
    serialGroupNameLabel.textColor = TEXTCOLOR;
    
    UIButton *queryButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.mainScrollView addSubview:queryButton];
    queryButton.frame = CGRectMake(5, 330, WIDTH - 10, 40);
    [queryButton setTitle:@"查询价格" forState:UIControlStateNormal];
    queryButton.backgroundColor = NEWBLUE;
    [queryButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    
}

#pragma mark --点击之后触发的方法
- (void)tapAction:(UITapGestureRecognizer *)tap {
    SHPictureViewController *picture = [[SHPictureViewController alloc] init];
    [self.navigationController pushViewController:picture animated:YES];
    [picture release];
    NSString *picUrl = [NSString stringWithFormat:@"http://mrobot.pcauto.com.cn/v2/price/nav_pictures?serialGroupId=%@&modelId=null", self.rightModel.myId];
    picture.nextStr = picUrl;
    picture.carId = self.rightModel.myId;
}

- (void)click:(UIButton *)button {
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
